using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using YouVisio.Silverlight.TextDiff.Extensions;

namespace YouVisio.Silverlight.TextDiffTests
{
    [TestClass]
    public class Extensions_Tests : BaseTestClass
    {
        #region String.FoldEachLine tests
        [TestMethod]
        public void String_Can_Fold_Each_Line()
        {
            const string str = "first line\nsecond line\nthird line";
            var lines = str.FoldEachLine(new List<string>(),
                                        (l, s) =>
                                        {
                                            l.Add(s);
                                            return l;
                                        });
            Assert.IsNotNull(lines);
            Assert.AreEqual(3, lines.Count);
            Assert.AreEqual("first line", lines[0]);
            Assert.AreEqual("second line", lines[1]);
            Assert.AreEqual("third line", lines[2]);
        }


        [TestMethod]
        public void String_Can_Fold_Each_Line_Within_Range()
        {
            const string str = "first line\nsecond line\nthird line\nfourth line\nfifth line";
            var lines = str.FoldEachLine(new List<string>(),
                                        (l, s) =>
                                        {
                                            l.Add(s);
                                            return l;
                                        }, 11, 45);
            Assert.IsNotNull(lines);
            Assert.AreEqual(3, lines.Count);
            Assert.AreEqual("second line", lines[0]);
            Assert.AreEqual("third line", lines[1]);
            Assert.AreEqual("fourth line", lines[2]);
        }
        #endregion

#region String.SameBeginningCompleteLines tests

//[TestMethod]
//public void Can_Find_Same_Beginning_Complete_Lines_Case_1()
//{
//    const string one = "first\nsecond\nthird\nfourth\nfifth";
//    const string two = "first\nsecond\nthirdXX\nfourthXX\nfifthXX";

//    var tuple = one.SameBeginningCompleteLines(two);
//    Assert.AreEqual("first\nsecond", tuple.Item1);
//    Assert.AreEqual("third\nfourth\nfifth", tuple.Item2);
//    Assert.AreEqual("thirdXX\nfourthXX\nfifthXX", tuple.Item3);
//}
//[TestMethod]
//public void Can_Find_Same_Beginning_Complete_Lines_Case_2()
//{
//    const string one = "first\nsecond\nthird\nfourth\nfifth";
//    const string two = "first\r\nsecond\nthirdXX\nfourthXX\nfifthXX";

//    var tuple = one.SameBeginningCompleteLines(two);
//    Assert.AreEqual("first\nsecond", tuple.Item1);
//    Assert.AreEqual("third\nfourth\nfifth", tuple.Item2);
//    Assert.AreEqual("thirdXX\nfourthXX\nfifthXX", tuple.Item3);
//}
//[TestMethod]
//public void Can_Find_Same_Beginning_Complete_Lines_Case_3()
//{
//    const string one = "first\rsecond\nthird\nfourth\nfifth";
//    const string two = "first\r\nsecond\nthirdXX\nfourthXX\nfifthXX";

//    var tuple = one.SameBeginningCompleteLines(two);
//    Assert.AreEqual("first\rsecond", tuple.Item1);
//    Assert.AreEqual("third\nfourth\nfifth", tuple.Item2);
//    Assert.AreEqual("thirdXX\nfourthXX\nfifthXX", tuple.Item3);
//}
//[TestMethod]
//public void Can_Find_Same_Beginning_Complete_Lines_Case_4()
//{
//    const string one = "first\r\nsecond\nthird\nfourth\nfifth";
//    const string two = "first\rsecond\nthirdXX\nfourthXX\nfifthXX";

//    var tuple = one.SameBeginningCompleteLines(two);
//    Assert.AreEqual("first\r\nsecond", tuple.Item1);
//    Assert.AreEqual("third\nfourth\nfifth", tuple.Item2);
//    Assert.AreEqual("thirdXX\nfourthXX\nfifthXX", tuple.Item3);
//}
//[TestMethod]
//public void Can_Find_Same_Beginning_Complete_Lines_Case_5()
//{
//    const string one = "first\r\nsecond\nthird\nfourth\nfifth";
//    const string two = "first\r\nsecond\nthirdXX\nfourthXX\nfifthXX";

//    var tuple = one.SameBeginningCompleteLines(two);
//    Assert.AreEqual("first\r\nsecond", tuple.Item1);
//    Assert.AreEqual("third\nfourth\nfifth", tuple.Item2);
//    Assert.AreEqual("thirdXX\nfourthXX\nfifthXX", tuple.Item3);
//}
//[TestMethod]
//public void Can_Find_Same_Beginning_Complete_Lines_Case_6()
//{
//    const string one = "first\n\rsecond\nthird\nfourth\nfifth";
//    const string two = "first\r\nsecond\nthirdXX\nfourthXX\nfifthXX";

//    var tuple = one.SameBeginningCompleteLines(two);
//    Assert.AreEqual("first", tuple.Item1);
//    Assert.AreEqual("\rsecond\nthird\nfourth\nfifth", tuple.Item2);
//    Assert.AreEqual("second\nthirdXX\nfourthXX\nfifthXX", tuple.Item3);
//}


//[TestMethod]
//public void Finding_Same_Beginning_Complete_Lines_Can_Recognize_Identical_Strings_Case_1()
//{
//    const string one = "first line\nsecond line\nthird line\nfourth line\nfifth line";
//    const string two = one;
//    var tuple = one.SameBeginningCompleteLines(two);

//    Assert.AreEqual(one, tuple.Item1);
//    AssertIsEmpty(tuple.Item2);
//    AssertIsEmpty(tuple.Item3);
//}
//[TestMethod]
//public void Finding_Same_Beginning_Complete_Lines_Can_Recognize_Identical_Strings_Case_2()
//{
//    const string one = "first line\nsecond line\r\nthird line\r\nfourth line\rfifth line";
//    const string two = "first line\r\nsecond line\nthird line\r\nfourth line\nfifth line";
//    var tuple = one.SameBeginningCompleteLines(two);

//    Assert.AreEqual(one, tuple.Item1);
//    AssertIsEmpty(tuple.Item2);
//    AssertIsEmpty(tuple.Item3);
//}

//[TestMethod]
//public void Finding_Same_Beginning_Complete_Lines_Can_Recognize_If_One_Is_Within_The_Other_Case_1()
//{
//    const string one = "first line\nsecond line\r\nthird line";
//    const string two = "first line\r\nsecond line\nthird line\r\nfourth line\nfifth line";
//    var tuple = one.SameBeginningCompleteLines(two);

//    Assert.AreEqual(one, tuple.Item1);
//    Assert.AreEqual("", tuple.Item2);
//    Assert.AreEqual("fourth line\nfifth line", tuple.Item3);
//}
//[TestMethod]
//public void Finding_Same_Beginning_Complete_Lines_Can_Recognize_If_One_Is_Within_The_Other_Case_2()
//{
//    const string one = "first line\nsecond line\r\nthird";
//    const string two = "first line\r\nsecond line\nthird line\r\nfourth line\nfifth line";
//    var tuple = one.SameBeginningCompleteLines(two);

//    Assert.AreEqual("first line\nsecond line", tuple.Item1);
//    Assert.AreEqual("third", tuple.Item2);
//    Assert.AreEqual("third line\r\nfourth line\nfifth line", tuple.Item3);
//}
//[TestMethod]
//public void Finding_Same_Beginning_Complete_Lines_Can_Recognize_If_One_Is_Within_The_Other_Case_3()
//{
//    const string one = "first line\nsecond line\r\nthird line\r\nfourth line\nfifth line";
//    const string two = "first line\r\nsecond line\nthird";
//    var tuple = one.SameBeginningCompleteLines(two);

//    Assert.AreEqual("first line\nsecond line", tuple.Item1);
//    Assert.AreEqual("third line\r\nfourth line\nfifth line", tuple.Item2);
//    Assert.AreEqual("third", tuple.Item3);
//}
//[TestMethod]
//public void Finding_Same_Beginning_Complete_Lines_Can_Recognize_If_One_Is_Within_The_Other_Case_4()
//{
//    const string one = "first line\nsecond line\r\nthird line\rfourth line\nfifth line";
//    const string two = "first line\r\nsecond line\nthird line";
//    var tuple = one.SameBeginningCompleteLines(two);

//    Assert.AreEqual("first line\r\nsecond line\nthird line", tuple.Item1);
//    Assert.AreEqual("fourth line\nfifth line", tuple.Item2);
//    Assert.AreEqual("", tuple.Item3);
//}
#endregion

#region String.SameEndingCompleteLines tests
//[TestMethod]
//public void Can_Find_Same_Ending_Complete_Lines_Case_1()
//{
//    const string one = "fiXXrst\nsXXecond\nthXXird\nfourth\nfifth";
//    const string two = "first\nsecond\nthird\nfourth\nfifth";

//    var tuple = one.SameEndingCompleteLines(two);
//    Assert.AreEqual("fiXXrst\nsXXecond\nthXXird", tuple.Item1);
//    Assert.AreEqual("first\nsecond\nthird", tuple.Item2);
//    Assert.AreEqual("fourth\nfifth", tuple.Item3);
//}
//[TestMethod]
//public void Can_Find_Same_Ending_Complete_Lines_Case_2()
//{
//    const string one = "firXXst\nseXXcond\nthirdXX\nfourth\nfifth";
//    const string two = "first\nsecond\nthird\r\nfourth\r\nfifth";

//    var tuple = one.SameEndingCompleteLines(two);
//    Assert.AreEqual("firXXst\nseXXcond\nthirdXX", tuple.Item1);
//    Assert.AreEqual("first\nsecond\nthird", tuple.Item2);
//    Assert.AreEqual("fourth\nfifth", tuple.Item3);
//}
//[TestMethod]
//public void Can_Find_Same_Ending_Complete_Lines_Case_3()
//{
//    const string one = "firXXst\nseXXcond\nthirdXX\nfourth\rfifth";
//    const string two = "first\nsecond\nthird\r\nfourth\r\nfifth";

//    var tuple = one.SameEndingCompleteLines(two);
//    Assert.AreEqual("firXXst\nseXXcond\nthirdXX", tuple.Item1);
//    Assert.AreEqual("first\nsecond\nthird", tuple.Item2);
//    Assert.AreEqual("fourth\rfifth", tuple.Item3);
//}
//[TestMethod]
//public void Can_Find_Same_Ending_Complete_Lines_Case_4()
//{
//    const string one = "firXXst\nseXXcond\nthirdXX\nfourth\r\nfifth";
//    const string two = "first\nsecond\nthird\r\nfourth\r\nfifth";

//    var tuple = one.SameEndingCompleteLines(two);
//    Assert.AreEqual("firXXst\nseXXcond\nthirdXX", tuple.Item1);
//    Assert.AreEqual("first\nsecond\nthird", tuple.Item2);
//    Assert.AreEqual("fourth\r\nfifth", tuple.Item3);
//}
//[TestMethod]
//public void Can_Find_Same_Ending_Complete_Lines_Case_5()
//{
//    const string one = "firXXst\nseXXcond\nthirdXX\nfourth\rfifth";
//    const string two = "first\nsecond\nthird\r\nfourth\nfifth";

//    var tuple = one.SameEndingCompleteLines(two);
//    Assert.AreEqual("firXXst\nseXXcond\nthirdXX", tuple.Item1);
//    Assert.AreEqual("first\nsecond\nthird", tuple.Item2);
//    Assert.AreEqual("fourth\rfifth", tuple.Item3);
//}
//[TestMethod]
//public void Can_Find_Same_Ending_Complete_Lines_Case_6()
//{
//    const string one = "firXXst\nseXXcond\nthirdXX\nfourth\r\nfifth";
//    const string two = "first\nsecond\nthird\r\nfourth\n\rfifth";

//    var tuple = one.SameEndingCompleteLines(two);
//    Assert.AreEqual("firXXst\nseXXcond\nthirdXX\nfourth", tuple.Item1);
//    Assert.AreEqual("first\nsecond\nthird\r\nfourth\n", tuple.Item2);
//    Assert.AreEqual("fifth", tuple.Item3);
//}
//[TestMethod]
//public void Finding_Same_Ending_Complete_Lines_Can_Recognize_Identical_Strings_Case_1()
//{
//    const string one = "first line\nsecond line\nthird line\nfourth line\nfifth line";
//    const string two = one;
//    var tuple = one.SameEndingCompleteLines(two);
//    AssertIsEmpty(tuple.Item1);
//    AssertIsEmpty(tuple.Item2);
//    Assert.AreEqual(one, tuple.Item3);

//}
//[TestMethod]
//public void Finding_Same_Ending_Complete_Lines_Can_Recognize_Identical_Strings_Case_2()
//{
//    const string one = "first line\nsecond line\r\nthird line\r\nfourth line\rfifth line";
//    const string two = "first line\r\nsecond line\nthird line\r\nfourth line\nfifth line";
//    var tuple = one.SameEndingCompleteLines(two);
//    AssertIsEmpty(tuple.Item1);
//    AssertIsEmpty(tuple.Item2);
//    Assert.AreEqual(one, tuple.Item3);
//}
#endregion

//private static void AssertIsEmpty(string str)
//{
//    Assert.IsTrue(str == "");
//}
    }
}